import cv2
image=cv2.imread('grad.png',cv2.IMREAD_GRAYSCALE)
cv2.imshow("Input",image)
kernel=cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
gradient =cv2.morphologyEx(image,cv2.MORPH_GRADIENT,kernel)
cv2.imshow("Input",image)
cv2.imshow("Gradient",gradient)
cv2.waitKey()
cv2.destroyAllWindows()